<template>
	<view class="content">
		<view class="text-area">
			<text class="title">{{title}}</text>
		</view>
	</view>
</template>

<script>
	import amap from "../../static/amap-wx.130.js"
	export default {
		data() {
			return {
				title:"",
				address:"",
				key:"91cad9f9a5d324b542db7c653236f190"
			}
		},
			onLoad() {
					this.amapPlugin = new amap.AMapWX({
						key: this.key
					});
					this.getAddress()

		},
		methods: {
					getAddress(){
							const _this = this;
							this.amapPlugin = new amap.AMapWX({
								key: this.key
							});
							uni.showLoading({
								title: '获取信息中'
							});
							// 成功获取位置
							_this.amapPlugin.getRegeo({
								success: (data) => {
									console.log(data, '当前定位')
									_this.address = `${data[0].regeocodeData.addressComponent.city}${data[0].regeocodeData.addressComponent.district}`;
									uni.hideLoading();
								},
								// 获取位置失败
								fail: (err) => {
									console.log(err)
									uni.showToast({
										title:"获取位置失败，请重启小程序",
										icon:"error"
									})
								}
							});
						}
		}
	}
</script>

<style>
	.content {
		display: flex;
		flex-direction: column;
		align-items: center;
		justify-content: center;
	}

	.logo {
		height: 200rpx;
		width: 200rpx;
		margin-top: 200rpx;
		margin-left: auto;
		margin-right: auto;
		margin-bottom: 50rpx;
	}

	.text-area {
		display: flex;
		justify-content: center;
	}

	.title {
		font-size: 36rpx;
		color: #8f8f94;
	}
</style>
